module.exports = (app) => {
    const BaseService = require('./base')(app);
    const modelList = require('../../model/index.js')(app);  
    
    return class ProjectService extends BaseService {
        /**
         * 获取项目配置
         */
        get({ projKey }) {
            let projConfig;

            modelList.forEach(item => {
                if (item.project[projKey] ) {
                    projConfig = item.project[projKey];
                }
            });

            return projConfig;
        }
        /**
         * 获取项目列表
         */
        getList({ projKey }) {
            return modelList.reduce((preList, modelItem) => {
                const { project } = modelItem;
                if (project && !project[projKey]) { return preList; } 
                
                for (const key in project) {
                    preList.push(
                        project[key]
                    );
                }

                return preList
            },[])
        }
        /**
         * 获取模型列表
         */
        async getModelList() {
            return modelList;
        }
    }
}  